<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
  String basePath = request.getContextPath();
  Object email = request.getSession().getAttribute("email");
%>
<!DOCTYPE HTML>
<html>
<head>
  <title>悬赏</title>
  <jsp:include page="../common/common-css.jsp"></jsp:include>
  <jsp:include page="../common/common-js.jsp"></jsp:include>
  <script type="application/javascript" src="<%=basePath%>/plugin/datepicker/bootstrap-datetimepicker.min.js"></script>
  <script type="application/javascript"
          src="<%=basePath%>/plugin/datepicker/bootstrap-datetimepicker.zh-CN.js"></script>
  <link rel="stylesheet" href="<%=basePath%>/plugin/datepicker/bootstrap-datetimepicker.min.css">
  <script type="application/javascript" src="<%=basePath%>/plugin/ajaxfileupload/ajaxfileupload.js"></script>
  <style>

  </style>
</head>
<body style="background-color: #f5f5f5">
<jsp:include page="../../head.jsp"></jsp:include>
<div class="container-fluid" style="padding: 0px">
  <div class="col-xs-0 col-sm-0 col-md-0 col-lg-0"></div>
  <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12" style="background-color: #ffffff;margin: 10px 0px;">
    <table style="width: 100%">
      <tr>
        <td class="writeSay" style="border-bottom: 1px solid blueviolet;padding: 15px;">
          在线留言&nbsp;<i class="icon-pencil"></i>
        </td>
        <td class="reward" style="border-bottom: 2px solid blueviolet;padding: 15px;" align="center">
          <i class="icon-bullhorn" style="color: #ffffff">&nbsp;悬赏</i>
        </td>
        <td class="auction" style="border-bottom: 1px solid #d3d3d3;padding: 15px;" align="center">
          <span style="color: #ffffff">拍卖&nbsp;</span><i class="icon-legal"style="color: #ffffff"></i>
        </td>
      </tr>
    </table>
    <div class="col-xs-12 col-sm-12 col-md-12 cl-lg-12" style="padding: 0px">
      <textarea rows="15" id="content"
                placeholder="在这儿输入留言......"
                style="resize: none;margin: 20px 0px;width: 100%;border: none"></textarea>
      <hr style="width: 100%;margin: 0px">
      <input type="text" onkeyup="this.value=this.value.replace(/\D/g,'')"
             onafterpaste="this.value=this.value.replace(/\D/g,'')"
             style="width: 100%;padding: 10px;border: none"
             id="fee" placeholder="￥赏金">

      <div style="background-color: #ffffff" class="address">
        <hr style="width: 100%;margin: 5px 0px">
        <table style="width: 100%;">
          <tr>
            <td style="padding: 0px 10px;width: 10px;color: darkgrey"><i class="icon-map-marker"></i></td>
            <td style="padding: 0px">
              <input type="text" style="border: none;width: 100%;padding: 10px 0px" id="address" placeholder="交易地点">
            </td>
          </tr>
        </table>
      </div>
      <div style="background-color: #ffffff;display: none" class="endtime">
        <hr style="width: 100%;margin: 5px 0px">
        <table style="width: 100%;">
          <tr>
            <td style="padding: 10px;width: 120px;color: darkgrey"><i class="icon-time">&nbsp;&nbsp;结束时间</i></td>
            <td align="right" style="padding: 5px">
              <div class="input-group">
                <input type="text" style="border: none;width: 100%" class="form_datetime" readonly id="endtime">
                      <span class="input-group-btn">
                        <a type="button" rel="popover">&nbsp;<i class="icon-calendar" style="color: blueviolet"></i>&nbsp;
                        </a>
                      </span>
              </div>
            </td>
          </tr>
        </table>
      </div>
      <div style="background-color: #ffffff;display: none" class="chooseImg">
        <hr style="width: 100%;margin: 5px 0px">
        <table style="width: 100%;">
          <tr>
            <td style="padding: 10px 8px;color: darkgrey">
              <i class="icon-picture icon-small" id="imgPath">&nbsp;&nbsp;选择图片</i>
            </td>
            <td align="right" style="padding-right: 15px;width: 20px">
              <i class="icon-angle-right"></i>
            </td>
          </tr>
        </table>
      </div>
      <input type="file" onchange="uploadFile(this);" name="filePath" id="filePath" style="display: none">

      <div style="background-color: #ffffff;" class="showPhone">
        <hr style="width: 100%;margin: 5px 0px">
        <table style="width: 100%;">
          <tr>
            <td style="padding: 10px;width: 120px;color: darkgrey"><i class="icon-phone">&nbsp;&nbsp;显示手机号</i></td>
            <td align="right" style="padding: 0px">
              <table style="margin: 5px;">
                <tr>
                  <td style="padding: 0px">
                    <a href="javascript:showMobile();">
                      <div class="showMobile" style="padding: 5px 15px;color: #ffffff;background-color: blueviolet">
                        是
                      </div>
                    </a>
                  </td>
                  <td style="padding: 0px">
                    <a href="javascript:notShowMobile();">
                      <div class="notShowMobile" style="padding: 5px 15px;color: #ffffff;background-color: #CCCCCC">
                        否
                      </div>
                    </a>
                  </td>
                </tr>
              </table>
            </td>
          </tr>
        </table>
      </div>
      <hr style="width: 100%;margin: 5px 0px">
      <button id="save" class="btn btn-default-color" style="margin: 15px">&nbsp;发&nbsp;布&nbsp;</button>
    </div>
  </div>
</div>
<input type="hidden" id="msgType" value="0">
<input type="hidden" id="isShowMobile" value="1">
<input type="hidden" id="img">
<jsp:include page="../../head.jsp"></jsp:include>
<jsp:include page="../common/common-html.jsp"></jsp:include>
</body>
<script language="JavaScript">


  // - 上传图片
  function uploadFile(obj) {
    $("#loadModal").modal({
      keyboard: false,
      backdrop: 'static'
    });
    var url = "<%=basePath%>/img/upload";
    $.ajaxFileUpload({
      url: url,
      fileElementId: "filePath",//file标签的id,
      dateType: "text",
      success: function (data, status) {
        // - ajaxFileUpload这儿必须得转换以下
        data = jQuery.parseJSON(jQuery(data).text());
        if (data.code == 200) {
          var temp = data.data;
          $("#img").val(temp.downloadUrl);
          $("#imgPath").text('  ' + temp.downloadUrl);
        } else {
          alerErr(data.msg);
        }
        $("#loadModal").modal('hide');
      },
      error: function (data, status, e) {
        $("#loadModal").modal('hide');
        $("#filePath").replaceWith($("#upload").clone(true));
        alerErr(e);
      }
    });
  }
  // - 触发上传图片
  $(".chooseImg").mousemove(function () {
    $(this).css("cursor", "pointer");
  })
  $(".chooseImg").mouseout(function () {
    $(this).css("cursor", "default");
  })
  $(".chooseImg").click(function () {
    var email = '<%=email%>';
    if (!validateEmail(email)) {
      return;
    }
    $("#filePath").click();
  })


  function showMobile() {
    $("#isShowMobile").val(1);
    $(".showMobile").css("background-color", "blueviolet");
    $(".notShowMobile").css("background-color", "#CCCCCC");
  }
  function notShowMobile() {
    $("#isShowMobile").val(0);
    $(".showMobile").css("background-color", "#CCCCCC");
    $(".notShowMobile").css("background-color", "blueviolet");
  }

  function writeSay() {
    $(".writeSay").css("border-bottom", "1px solid blueviolet");
    $(".writeSay").css("color", "blueviolet");
    $(".reward").css("border-bottom", "1px solid #d3d3d3");
    $(".reward").css("color", "#000000");
    $(".auction").css("border-bottom", "1px solid #d3d3d3");
    $(".auction").css("color", "#000000");
    $("#fee").hide();
    $(".endtime").hide();
    $(".chooseImg").hide();
    $(".address").hide();
    $(".showPhone").hide();
    $("#msgType").val(1);
  }
  function reward() {
    $(".reward").css("border-bottom", "2px solid blueviolet");
    $(".reward").css("color", "blueviolet");
    $(".writeSay").css("border-bottom", "1px solid #d3d3d3");
    $(".writeSay").css("color", "#000000");
    $(".auction").css("border-bottom", "1px solid #d3d3d3");
    $(".auction").css("color", "#000000");
    $("#fee").show();
    $(".showPhone").show();
    $(".chooseImg").show();
    $(".endtime").hide();
    $(".address").show();
    $("#msgType").val(0);
    $("#fee").attr("placeholder", "￥赏金");
  }
  function auction() {
    $(".auction").css("border-bottom", "2px solid blueviolet");
    $(".auction").css("color", "blueviolet");
    $(".writeSay").css("border-bottom", "1px solid #d3d3d3");
    $(".writeSay").css("color", "#000000");
    $(".reward").css("border-bottom", "1px solid #d3d3d3");
    $(".reward").css("color", "#000000");
    $("#fee").show();
    $(".address").show();
    $(".chooseImg").show();
    $(".endtime").show();
    $(".showPhone").show();
    $("#fee").attr("placeholder", "￥起拍价");
    $("#msgType").val(2);
  }
  function initMsgType(type) {
    if (type == 0) {
      // - 悬赏
      reward();
    } else if (type == 1) {
      // - 留言
      writeSay();
    } else if (type == 2) {
      // - 拍卖
      auction();
    }
  }
  $(function () {
    initMsgType(${type});
    initStyle();
    // - 日期选择器
    $("#endtime").datetimepicker({
      format: "yyyy-mm-dd hh:ii:ss",
      autoclose: true,
      todayBtn: true,
      todayHighlight: true,
      minView: "hour",
      language: "zh-CN",
      todayHighlight: true
    });

//    $(".writeSay").mousemove(function () {
//      $(this).css("cursor", "pointer");
//    })
//    $(".reward").mousemove(function () {
//      $(this).css("cursor", "pointer");
//    })
//    $(".auction").mousemove(function () {
//      $(this).css("cursor", "pointer");
//    })
    // - 反馈
    $("#save").click(function () {
      var email = '<%=email%>';
      if (!validateEmail(email)) {
        return;
      }
      var content = $.trim($("#content").val());
      var fee = $("#fee").val();
      var endTime = $.trim($("#endtime").val());
      var msgType = $.trim($("#msgType").val());
      var isShowMobile = $("#isShowMobile").val();
      var img = $("#img").val();
      var address = $.trim($('#address').val());
      if (content == "") {
        alerErr("输入内容");
        return;
      }
      if (msgType == "0") {
        if (fee == '') {
          // - 悬赏
          alerErr("输入赏金");
          return;
        }
        if (address == '') {
          alerErr("输入交易地点");
          return;
        }
        if (img == '') {
          alerErr("选择图片");
          return;
        }
      }
      if (msgType == "2") {
        // - 拍卖
        if (fee == '') {
          alerErr("输入起拍价");
          return;
        }
        if (address == '') {
          alerErr("输入交易地点");
          return;
        }
        if (endTime == '') {
          alerErr("选择截止时间");
          return;
        }
        if (img == '') {
          alerErr("选择图片");
          return;
        }
      }
      var param = {
        content: content,
        msgType: msgType,
        fee: fee,
        isShowMobile: isShowMobile,
        endTime: endTime,
        img: img,
        address: address
      };
      var url = "<%=basePath%>/advice/add";
      $.post(url, param, function (data, status) {
        if (data.code == 200) {
          $("#content").val('');
          $("#fee").val('');
          $("#endtime").val('');
          $("#msgType").val('');
          $("#address").val('');
          $("#isShowMobile").val(1);
          var backUrl = '';
          if (msgType == 0) {
            // - 悬赏
            backUrl = '<%=basePath%>/reward?type=0&status=0';
          } else if (msgType == 1) {
            // - 留言
            backUrl = '<%=basePath%>/note?type=1&status=0';
          } else if (msgType == 2) {
            // - 拍卖
            backUrl = '<%=basePath%>/auction?type=2&status=0';
          }
          window.location = backUrl;
        } else {
          aler(data);
        }
      })
    })

    $(".writeSay").click(function () {
      writeSay();
    })
  })
</script>
</html>
